@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form layui-form-pane" id="office-app-form" lay-filter="office-app-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用名称</label>
                        <div class="layui-input-block">
                            <input class="layui-input" type="text" name="name" value="{{$data['name'] ?? ''}}" placeholder="请输入名称" autocomplete="off" lay-verify="required" required />
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <input type="button" value="添加" id="submit-create" lay-submit lay-filter="submit-create" />
                        <input type="button" value="更新" id="submit-update" lay-submit lay-filter="submit-update" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index', 'system'], function () {
            // 创建
            layui.form.on('submit(submit-create)', function (data) {
                // 获取提交的字段
                var formField = data.field;
                // 当前iframe层的索引
                var layerIndex = parent.layer.getFrameIndex(window.name);
                // ajax提交
                layui.$.ajax({
                    url: layui.setter.apiLink + '/office/admin_app/create',
                    type: 'POST',
                    data: formField,
                    success: function (result) {
                        console.log('提交结果：', result);
                        window.SOURCE_WINDOW.layui.table.reload('office-app-list');
                    }
                });
            });
            // 更新
            layui.form.on('submit(submit-update)', function (data) {
                // 获取提交的字段
                var formField = data.field;
                formField.content = layui.layedit.getContent(layuiEdit);
                console.log('表单字段：', formField);
                // 当前iframe层的索引
                var layerIndex = parent.layer.getFrameIndex(window.name);
                // ajax提交
                layui.$.ajax({
                    url: layui.setter.apiLink + '/office/admin_app/update?id={{$data['id'] ?? 0}}',
                    type: 'POST',
                    data: formField,
                    success: function (result) {
                        console.log('提交结果：', result);
                        // 重载表格
                        parent.layui.table.reload('office-app-list');
                        // 关闭弹层
                        parent.layer.close(layerIndex);
                    }
                });
            });
        });
    </script>
@endsection